package com.jasmine.bjstkserver.server.article.log.viewlog;

import com.jasmine.bjstkserver.manager.ip.IpDTO;
import com.jasmine.bjstkserver.manager.ip.IpManager;
import com.jasmine.bjstkserver.server.article.online.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author jasmineXz
 */
@Component
public class ArticleViewLogClickHandler {


    @Autowired
    private ArticleService articleService;

    @Autowired
    private ViewLogService viewLogService;

    @Autowired
    private IpManager ipManager;

    public void execute (ViewLogEntity viewLog) {
        IpDTO ipDTO = ipManager.query(viewLog.getRemoteAddr().trim());
        viewLog.setType("CLICK");
        if (ipDTO != null) {
            viewLog.setProvince(ipDTO.getProvince());
            viewLog.setCity(ipDTO.getCity());
        }
        viewLogService.insert(viewLog);

        articleService.clickIncrease(viewLog.getArticleId());
    }
}
